@extends('admin.formLayout')
@if(isset($id))
    @section('title','编辑权限')
@section('barName','编辑权限')
@else
    @section('title','添加权限')
@section('barName','添加权限')
@endif
@section('content')
    <form class="layui-form" @if(!isset($id)) action="{{route('admin.permission-add')}}" @else action="{{route('admin.permission-edit',['id'=>$id])}}" @endif method="post">
        <div class="layui-tab" lay-filter="posts">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                        <div class="layui-col-md8">
                            {{csrf_field()}}
                            @if(isset($id))
                                <input type="hidden" name="id" value="{{$id}}">
                            @endif
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限名称<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" lay-verify="required"  value="@if(old('name')){{old('name')}}@else{{$model->name or ''}}@endif" autocomplete="off" placeholder="请输入权限名称" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">描述<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <textarea  name="desc"   class="layui-textarea" placeholder="" lay-verify="required" >@if(old('desc')){{old('desc')}}@else{{$model->desc or ''}}@endif</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">组名<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <input list="group_names" type="text" name="group_name"   value="@if(old('group_name')){{old('group_name')}}@else{{$model->group_name or ''}}@endif" autocomplete="off" placeholder="" class="layui-input" lay-verify="required">
                                    <datalist id="group_names">
                                        @foreach($group as $k=>$v)
                                            <option value="{{$v}}">{{$v}}</option>
                                        @endforeach
                                    </datalist>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">监听组<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <select lay-verify="required" name="guard_name">
                                        @foreach($guard as $k=>$v)
                                            <option value="{{$v}}" @if(old('guard_name')){{(old('guard_name')==$v)?'selected':''}}@else{{ (isset($model->guard_name)&&$model->guard_name==$v) ?'selected':''}} @endif>{{$v}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                <button type="button"  onclick="javascript:location.href='{{route('admin.permission')}}'" class="layui-btn layui-btn-primary">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
@endsection
@section('script')

    <script>
        layui.use(['element','form','layer','upload'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            @if (count($errors) > 0)
            @foreach ($errors->all() as $error)
        layer.msg('{{$error}}',{'icon':2});
            @break
            @endforeach
            @endif

        });
    </script>
@endsection